/*
 * Copyright © 2022-now 尛飛俠（Denvie） All rights reserved.
 */

package cn.denvie.springboot.dds.config;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * 数据源配置。
 *
 * @author Denvie
 * @date 2022/3/28
 * @since 1.0.0
 */
@Configuration
@ConditionalOnProperty(name = "spring.profiles.active", havingValue = "jdbc")
public class DataSourceConfig {
    @Bean("dataSource1")
    @ConfigurationProperties("spring.datasource.ds1")
    public DataSource dataSource1() {
        // 系统会根据 spring.datasource.ds1 配置自动创建一个 DruidDataSource
        return DruidDataSourceBuilder.create().build();
    }

    @Bean("dataSource2")
    @ConfigurationProperties("spring.datasource.ds2")
    public DataSource dataSource2() {
        // 系统会根据 spring.datasource.ds2 配置自动创建一个 DruidDataSource
        return DruidDataSourceBuilder.create().build();
    }
}
